package org.erepublik.company.product;

import org.erepublik.company.Company;
import org.erepublik.company.ECountry;
import org.erepublik.company.EProductType;
import org.json.JSONException;
import org.json.JSONObject;

public class Raw extends Product {

    private boolean moreOffers =false;
    private int offerNumbers = 1;
    
    
    public boolean isMoreOffers() {
        return moreOffers;
    }




    public void setMoreOffers(boolean moreOffers) {
        this.moreOffers = moreOffers;
    }




    public int getOfferNumbers() {
        return offerNumbers;
    }




    public void setOfferNumbers(int offerNumbers) {
        this.offerNumbers = offerNumbers;
    }




    public Raw(EProductType productType) {
        super(productType);
    }
    
    
    
    
    public static Raw getRawFromJSON(JSONObject object) throws JSONException {
        EProductType productType = EProductType.valueOf( object.get("productType").toString() );
        Raw product = new Raw(productType);
        
        String companyName = "no name";
        if (object.has("companyName"))
            companyName = (String)object.get("companyName");
        product.setCompanyOwner( new Company( (Integer)object.get("companyOwner"), 0, ECountry.valueOf( (String) object.get("companyCountry") ),companyName ));
        product.setMarket(ECountry.valueOf( (String) object.get("market") ) );
        if (object.get("price") instanceof Integer)
            product.setPrice( (Integer)object.get("price") );
        else
            product.setPrice( (Double)object.get("price") );
        if (object.get("priceInGold") instanceof Integer)
            product.setPriceInGold( (Integer)object.get("priceInGold") );
        else
            product.setPriceInGold( (Double)object.get("priceInGold") );
        product.setQuantity((Integer)object.get("quantity"));
        
        return product;
    }
    
    

    @Override
    public JSONObject toJSONObject() throws JSONException {
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("productType", getProductType());
        jsonObj.put("companyOwner", getCompanyOwner().getId());
        jsonObj.put("companyCountry", getCompanyOwner().getCountry());
        jsonObj.put("market", getCountry().toString());
        jsonObj.put("price", getPrice());
        jsonObj.put("priceInGold", getPriceInGold());
        jsonObj.put("quantity", getQuantity());
        return jsonObj;
    }
    
    
    
    public Raw clone() {
       return (Raw) super.clone();
      
    }
    

}
